<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends Public_Controller {

	public function __construct()
	{
  		parent::Public_Controller();
  		$this->lang->load('home/home');
	}
	
	public function index()
	{
//		Articles and Categories
		$this->load->model('articles/articles_model', 'articles_m');
		$this->load->model('categories/categories_model', 'categories_m');
		
		$categories = $this->categories_m->get_lang_list(array($this->categories_m->get_table(). '.id <=' => '5'), CURRENT_LANGUAGE);
		$articles = $this->articles_m->get_lang_list(array('where_in' => array('category_id' => array(1,2,3,4,5))), CURRENT_LANGUAGE);
		$news = $this->articles_m->get_lang_list(array('category_id' => 6, 'limit' => 5, 'order_by' => 'created DESC'), CURRENT_LANGUAGE);
		
// 		Channels and Cities
		$this->load->model('regions/regions_model', 'regions_m');
		$this->load->model('channels/channels_model', 'channels_m');
		$channels = $this->channels_m->get_lang_list(array('visible' => '1'), CURRENT_LANGUAGE);
		$regions = $this->regions_m->get_lang_list(array('region_type' => '3'), CURRENT_LANGUAGE);
		
// 		Top east
		$this->load->model('tours/tours_model', 'tours_m');
		$tours_east = $this->tours_m->get_lang_list(array('channel_id' => 1, 'limit' => 5, 'order_by' => 'view_count DESC, created DESC'), CURRENT_LANGUAGE);
		$tours_west = $this->tours_m->get_lang_list(array('channel_id' => 2, 'limit' => 5, 'order_by' => 'view_count DESC, created DESC'), CURRENT_LANGUAGE);
		
// 		Special Price
		$tours_specialprice = $this->tours_m->get_lang_list(array('limit' => 5, 'order_by' => '(price-discountprice) DESC'), CURRENT_LANGUAGE);
		
// 		p($tours_specialprice);
		$this->template->set('layout','home')->load('index.php', array(
			'tours_east' => $tours_east,		
			'tours_west' => $tours_west,		
			'tours_specialprice' => $tours_specialprice,		
			'news' => $news,		
			'categories' => $categories,		
			'articles' => $articles,
			'channels' => $channels,		
			'regions' => $regions
		));
	}
	
	public function article($article_id){
		
		$this->load->model('articles/articles_model', 'articles_m');
		$article = $this->articles_m->_get(intval($article_id), CURRENT_LANGUAGE);
		if(empty($article)){
			redirect(site_url());
		}
		p($article);
		$this->template->set('layout','home')->load('index.php', array(
				'article' => $article
		));
	}
	
	public function region($region_id){
		
	}
	
	public function channel($channel_id){
		
	}
	
	public function googleweather($zone = '10001')
	{
// 		google weather api
		list($information, $current, $forecast_list) = getGoogleWeatherApi($zone);
		
		$this->template->set('layout','ajax')->load('google_weather.php', array(
			'information' => $information,		
			'current' => $current,		
			'zone' => $zone,		
			'forecast_list' => $forecast_list	
		));
	}
	public function googleweathers()
	{
// 		google weather api
		list($information, $current, $forecast_list) = getGoogleWeatherApi('10001');
		list($information2, $current2, $forecast_list2) = getGoogleWeatherApi('98101');
		list($information3, $current3, $forecast_list3) = getGoogleWeatherApi('90001');
		
		$this->template->set('layout','ajax')->load('google_weathers.php', array(
			'information' => $information,		
			'current' => $current,		
			'forecast_list' => $forecast_list,	
			'information2' => $information2,		
			'current2' => $current2,		
			'forecast_list2' => $forecast_list2,	
			'information3' => $information3,		
			'current3' => $current3,		
			'forecast_list3' => $forecast_list3	
		));
	}
}